/*
 * AlphaBetaWithMemory.h
 *
 *  Created on: 21/06/2011
 *      Author: frandres
 */

#ifndef MTDF_
#define MTDF_

#define MAX(s,t)      ((s)>(t)?(s):(t))
#define MIN(s,t)      ((s)<(t)?(s):(t))

#include "othelloTranspositionNode.h"
#include <tr1/unordered_map>
#include <limits.h>

#define MIN_VALUE 0
#define MAX_VALUE 72
#define MAX_NUMBER_OF_NODES 70000000 // Calculado para 5.25 Gigas, suponiendo que cada nodo pesa 11 bytes.
class MTDF {
public:
	MTDF();
	~MTDF();

	// Definición del hash para la tabla de transposición:

	typedef struct
	{
		long operator() (unsigned int key) const
		{
			return key*2654435761 % 4294967295;
		}
	} HashFunction;

	typedef struct
	{
		bool operator() (const unsigned int x, const unsigned int y) const
		{
			return x == y;
		}
	} EqFuntion;

	typedef std::tr1::unordered_multimap<unsigned int, OthelloTranspositionTableNode *, HashFunction, EqFuntion> Hash;

	inline unsigned int getNumberOfNodes(){
		return numberOfNodes;
	}

	inline  int getGameValue(){
			return gameValue;
		}

	inline void incrementNumberOfNodes(){
			 numberOfNodes++;
		}

	int gameValue;
	unsigned int numberOfNodes;

	Hash * transpositionTable;

	// Métodos:

	int run(OthelloTranspositionTableNode * n, int alpha , int beta , int d,bool isBlack);

	int mtdf(OthelloTranspositionTableNode * n, int f , int d,bool isBlack);

};

#endif /* ALPHABETAWITHMEMORY_H_ */
